﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Engine.Transactions {
    import flash.events.*;
    import flash.utils.*;

    public class TPublishUserAction extends Transaction {

        protected static const FEED_CALLBACK_TIMEOUT:Number = 15;
        protected static const AUTO_PUBLISH_DELAY:Number = 5000;

        protected static var m_category:String = "";
        protected static var m_subcategory:String = "";
        protected static var m_creative:String = "";

        protected var m_action:String;
        protected var m_bundleData:Object;
        protected var m_oneLine:Boolean;
        protected var m_strTargetIds:Array;
        protected var m_closeCallback:Function = null;
        protected var m_askPermissions:Boolean;
        protected var m_autoPublish:Boolean = false;
        protected var m_userMessage:String = "";
        protected var m_autoPublishTimer:Timer;

        public function TPublishUserAction(_arg1:String, _arg2:Object, _arg3:Array, _arg4:Boolean, _arg5:Function=null, _arg6:int=0, _arg7:Boolean=false, _arg8:Boolean=false, _arg9:String=""){
            var _local10:int;
            this.m_strTargetIds = new Array();
            super();
            this.m_action = _arg1;
            this.m_bundleData = _arg2;
            this.m_oneLine = _arg4;
            this.m_closeCallback = _arg5;
            this.m_askPermissions = _arg7;
            if (this.m_closeCallback != null){
                if (_arg6 <= 0){
                    _arg6 = FEED_CALLBACK_TIMEOUT;
                };
                if (GlobalEngine.feedCallbackTimer == null){
                    GlobalEngine.feedCallbackTimer = new Timer((_arg6 * 1000));
                    GlobalEngine.feedCallbackTimer.addEventListener(TimerEvent.TIMER, this.onCloseCallback, false, 0, true);
                    GlobalEngine.feedCallbackTimer.start();
                };
                GlobalEngine.onFeedCloseCallback = this.onCloseCallback;
            };
            if (_arg3){
                _local10 = 0;
                while (_local10 < _arg3.length) {
                    this.m_strTargetIds.push(_arg3[_local10].toString());
                    _local10++;
                };
            };
        }
        public static function get category():String{
            return (m_category);
        }
        public static function get subcategory():String{
            return (m_subcategory);
        }
        public static function get creative():String{
            return (m_creative);
        }

        override public function perform():void{
            signedCall("UserService.publishUserAction", this.m_action, this.m_bundleData, this.m_strTargetIds, this.m_oneLine);
        }
        override protected function onComplete(_arg1:Object):void{
            if (((_arg1.showFeedDialog) && ((this.m_oneLine == false)))){
                if (((this.m_askPermissions) && (!(GlobalEngine.socialNetwork.userHasStreamPermissions())))){
                    GlobalEngine.socialNetwork.showStreamPermissions(this.onFinishStreamPermissions);
                } else {
                    m_category = _arg1.category;
                    m_subcategory = _arg1.subcategory;
                    m_creative = _arg1.creative;
                    this.streamPublish();
                };
            };
        }
        protected function streamPublish():void{
            var _local1:String;
            if (this.m_strTargetIds.length > 0){
                _local1 = this.m_strTargetIds[0].toString();
            };
            GlobalEngine.socialNetwork.streamPublish(m_rawResult.data.attachment, m_rawResult.data.actionLink, _local1, m_rawResult.data.userMessagePrompt, null, this.m_autoPublish, this.m_userMessage);
        }
        protected function onFinishStreamPermissions():void{
            if (GlobalEngine.socialNetwork.userHasStreamPermissions()){
                this.m_autoPublishTimer = new Timer(AUTO_PUBLISH_DELAY, 1);
                this.m_autoPublishTimer.addEventListener(TimerEvent.TIMER, this.onPublishDelayComplete);
                this.m_autoPublishTimer.start();
            } else {
                this.streamPublish();
            };
        }
        protected function onPublishDelayComplete(_arg1:TimerEvent):void{
            if (this.m_autoPublishTimer != null){
                this.m_autoPublishTimer.removeEventListener(TimerEvent.TIMER, this.onPublishDelayComplete);
                this.m_autoPublishTimer = null;
            };
            this.streamPublish();
        }
        protected function onCloseCallback(_arg1:TimerEvent):void{
            GlobalEngine.onFeedCloseCallback = null;
            GlobalEngine.socialNetwork.onFeedClosed();
            if (this.m_closeCallback != null){
                this.m_closeCallback();
            };
        }

    }
}//package Engine.Transactions 
